package com.htj.powerbank.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.htj.powerbank.entity.Shop;
import com.htj.powerbank.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    ShopService shopService;

    @GetMapping("/listall")
    public R listAll(){
        return R.ok(shopService.getShopListAll());
    }

    @GetMapping("/listbyid")
    public R listbyid(@RequestParam("id") int id){
        System.out.println(id);
        return R.ok(shopService.getShopListbyid(id));
    }

    @GetMapping("/list")
    public R list(@RequestParam("pageNum") int pageNum,
                  @RequestParam("pageSize") int pageSize,
                  @RequestParam("sort") String sort,
                  Shop shop){
        Boolean isDesc = new Boolean(sort.equals("+id"));
//        System.out.println(isDesc);
        Page<Shop> page = new Page<>(pageNum, pageSize);
        IPage<Shop> queryVoPage = shopService.getShopList(page,shop,isDesc);
        return R.ok(queryVoPage);
    }
}
